package info.hexin.img;

import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
import org.jdom2.Element;
import org.jdom2.Text;

import java.net.URL;
import java.net.URLConnection;
import java.util.List;

/**
 * Created by infi.he on 2016/2/16.
 */
public class FetchImg {
    public static void main(String[] args) throws Exception {
        URL feedUrl = new URL("https://www.stylewe.com/feed/facebook_base/mpa?medium=YMDPA");
        SyndFeedInput input = new SyndFeedInput();
        input.setAllowDoctypes(true);
        URLConnection urlConnection = feedUrl.openConnection();
        urlConnection.setConnectTimeout(3 * 60 * 1000);
        urlConnection.setReadTimeout(3 * 60 * 1000);
        SyndFeed feed = input.build(new XmlReader(urlConnection));
        // 得到Rss新闻中子项列表
        List entries = feed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            SyndEntry entry = (SyndEntry) entries.get(i);
            List<Element> foreignMarkup = entry.getForeignMarkup();
            String id = null, image_link = null, price = null;
            for (Element element : foreignMarkup) {
                String value = element.getContent().get(0).getValue();
                switch (element.getName()) {
                    case "id":
                        id = value;
                        break;
                    case "image_link":
                        image_link = value;
                        break;
                    case "price":
                        price = value;
                        break;
                    default:
//                      System.out.println(element);
                }
            }
            System.out.println("id>>" + id + ";image_link>>" + image_link + ";price>>" + price);
        }
    }
}
